package l1j.opqlo.C_ItemUse_PART2;

import l1j.server.echo.ClientThread;
import l1j.server.server.datatables.SkillsTable;
import l1j.server.server.datatables.lock.CharSkillReading;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_AddSkill;
import l1j.server.server.serverpackets.S_ServerMessage;
import l1j.server.server.serverpackets.S_SkillSound;
import l1j.server.server.templates.L1Skills;

public class C_SpellBooks {

	private static void SpellBook(L1PcInstance pc, L1ItemInstance item) {
		String s = "";
		int i = 0;
		int level1 = 0;
		int level2 = 0;
		int l = 0;
		int i1 = 0;
		int j1 = 0;
		int k1 = 0;
		int l1 = 0;
		int i2 = 0;
		int j2 = 0;
		int k2 = 0;
		int l2 = 0;
		int i3 = 0;
		int j3 = 0;
		int k3 = 0;
		int l3 = 0;
		int i4 = 0;
		int j4 = 0;
		int k4 = 0;
		int l4 = 0;
		int i5 = 0;
		int j5 = 0;
		int k5 = 0;
		int l5 = 0;
		int i6 = 0;
		for (int skillId = 1; skillId < 81; skillId++) {
			final L1Skills l1skills = SkillsTable.getInstance().getTemplate(skillId);
			final String s1 = "魔法書 (" + l1skills.getName() + ")";
			if (item.getItem().getName().equalsIgnoreCase(s1)) {
				final int skillLevel = l1skills.getSkillLevel();
				final int i7 = l1skills.getId();
				s = l1skills.getName();
				i = l1skills.getSkillId();
				switch (skillLevel) {
				case 1: // '\001'
					level1 = i7;
					break;

				case 2: // '\002'
					level2 = i7;
					break;

				case 3: // '\003'
					l = i7;
					break;

				case 4: // '\004'
					i1 = i7;
					break;

				case 5: // '\005'
					j1 = i7;
					break;

				case 6: // '\006'
					k1 = i7;
					break;

				case 7: // '\007'
					l1 = i7;
					break;

				case 8: // '\b'
					i2 = i7;
					break;

				case 9: // '\t'
					j2 = i7;
					break;

				case 10: // '\n'
					k2 = i7;
					break;

				case 11: // '\013'
					l2 = i7;
					break;

				case 12: // '\f'
					i3 = i7;
					break;

				case 13: // '\r'
					j3 = i7;
					break;

				case 14: // '\016'
					k3 = i7;
					break;

				case 15: // '\017'
					l3 = i7;
					break;

				case 16: // '\020'
					i4 = i7;
					break;

				case 17: // '\021'
					j4 = i7;
					break;

				case 18: // '\022'
					k4 = i7;
					break;

				case 19: // '\023'
					l4 = i7;
					break;

				case 20: // '\024'
					i5 = i7;
					break;

				case 21: // '\025'
					j5 = i7;
					break;

				case 22: // '\026'
					k5 = i7;
					break;

				case 23: // '\027'
					l5 = i7;
					break;

				case 24: // '\030'
					i6 = i7;
					break;
				}
			}
		}

		final int objid = pc.getId();
		pc.sendPackets(new S_AddSkill(pc, level1, level2, l, i1, j1, k1, l1,
				i2, j2, k2, l2, i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5,
				i6, 0, 0, 0, 0));
		// S_SkillSound s_skillSound = new S_SkillSound(objid, isLawful ? 224:
		// 231);

		pc.sendPacketsX8(new S_SkillSound(objid, 231));
		CharSkillReading.get().spellMastery(objid, i, s, 0, 0);
		pc.getInventory().removeItem(item, 1);
		pc.setSkillMastery(i);
	}

	public static void SpellBook1(L1PcInstance pc,
			L1ItemInstance l1iteminstance, ClientThread clientthread) {
		String s = "";
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;
		int i1 = 0;
		int j1 = 0;
		int k1 = 0;
		int l1 = 0;
		int i2 = 0;
		int j2 = 0;
		int k2 = 0;
		int l2 = 0;
		int i3 = 0;
		int j3 = 0;
		int k3 = 0;
		int l3 = 0;
		int i4 = 0;
		int j4 = 0;
		int k4 = 0;
		int l4 = 0;
		int i5 = 0;
		int j5 = 0;
		int k5 = 0;
		int l5 = 0;
		int i6 = 0;
		for (int j6 = 97; j6 < 112; j6++) {
			final L1Skills l1skills = SkillsTable.getInstance().getTemplate(j6);
			final String s1 = "黑暗精靈水晶(" + l1skills.getName() + ")";
			if (l1iteminstance.getItem().getName().equalsIgnoreCase(s1)) {
				final int l6 = l1skills.getSkillLevel();
				final int i7 = l1skills.getId();
				s = l1skills.getName();
				i = l1skills.getSkillId();
				switch (l6) {
				case 1: // '\001'
					j = i7;
					break;

				case 2: // '\002'
					k = i7;
					break;

				case 3: // '\003'
					l = i7;
					break;

				case 4: // '\004'
					i1 = i7;
					break;

				case 5: // '\005'
					j1 = i7;
					break;

				case 6: // '\006'
					k1 = i7;
					break;

				case 7: // '\007'
					l1 = i7;
					break;

				case 8: // '\b'
					i2 = i7;
					break;

				case 9: // '\t'
					j2 = i7;
					break;

				case 10: // '\n'
					k2 = i7;
					break;

				case 11: // '\013'
					l2 = i7;
					break;

				case 12: // '\f'
					i3 = i7;
					break;

				case 13: // '\r'
					j3 = i7;
					break;

				case 14: // '\016'
					k3 = i7;
					break;

				case 15: // '\017'
					l3 = i7;
					break;

				case 16: // '\020'
					i4 = i7;
					break;

				case 17: // '\021'
					j4 = i7;
					break;

				case 18: // '\022'
					k4 = i7;
					break;

				case 19: // '\023'
					l4 = i7;
					break;

				case 20: // '\024'
					i5 = i7;
					break;

				case 21: // '\025'
					j5 = i7;
					break;

				case 22: // '\026'
					k5 = i7;
					break;

				case 23: // '\027'
					l5 = i7;
					break;

				case 24: // '\030'
					i6 = i7;
					break;
				}
			}
		}

		final int k6 = pc.getId();
		pc.sendPackets(new S_AddSkill(pc, j, k, l, i1, j1, k1, l1, i2, j2, k2,
				l2, i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5, i6, 0, 0,
				0, 0));
		pc.sendPacketsX8(new S_SkillSound(k6, 231));
		CharSkillReading.get().spellMastery(k6, i, s, 0, 0);
		pc.getInventory().removeItem(l1iteminstance, 1);
		pc.setSkillMastery(i);
	}

	private static void SpellBook2(L1PcInstance pc,
			L1ItemInstance l1iteminstance) {
		String s = "";
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;
		int i1 = 0;
		int j1 = 0;
		int k1 = 0;
		int l1 = 0;
		int i2 = 0;
		int j2 = 0;
		int k2 = 0;
		int l2 = 0;
		int i3 = 0;
		int j3 = 0;
		int k3 = 0;
		int l3 = 0;
		int i4 = 0;
		int j4 = 0;
		int k4 = 0;
		int l4 = 0;
		int i5 = 0;
		int j5 = 0;
		int k5 = 0;
		int l5 = 0;
		int i6 = 0;
		for (int j6 = 129; j6 <= 176; j6++) {
			final L1Skills l1skills = SkillsTable.getInstance().getTemplate(j6);
			final String s1 = "精靈水晶(" + l1skills.getName() + ")";
			if (l1iteminstance.getItem().getName().equalsIgnoreCase(s1)) {
				if (!pc.isGm() && l1skills.getAttr() != 0
						&& pc.getElfAttr() != l1skills.getAttr()) {
					if (pc.getElfAttr() == 0 || pc.getElfAttr() == 1
							|| pc.getElfAttr() == 2 || pc.getElfAttr() == 4
							|| pc.getElfAttr() == 8) { // 屬性值が異常な場合は全屬性を覺えられるようにしておく
						pc.sendPackets(new S_ServerMessage(79));
						return;
					}
				}
				final int l6 = l1skills.getSkillLevel();
				final int i7 = l1skills.getId();
				s = l1skills.getName();
				i = l1skills.getSkillId();
				switch (l6) {
				case 1: // '\001'
					j = i7;
					break;

				case 2: // '\002'
					k = i7;
					break;

				case 3: // '\003'
					l = i7;
					break;

				case 4: // '\004'
					i1 = i7;
					break;

				case 5: // '\005'
					j1 = i7;
					break;

				case 6: // '\006'
					k1 = i7;
					break;

				case 7: // '\007'
					l1 = i7;
					break;

				case 8: // '\b'
					i2 = i7;
					break;

				case 9: // '\t'
					j2 = i7;
					break;

				case 10: // '\n'
					k2 = i7;
					break;

				case 11: // '\013'
					l2 = i7;
					break;

				case 12: // '\f'
					i3 = i7;
					break;

				case 13: // '\r'
					j3 = i7;
					break;

				case 14: // '\016'
					k3 = i7;
					break;

				case 15: // '\017'
					l3 = i7;
					break;

				case 16: // '\020'
					i4 = i7;
					break;

				case 17: // '\021'
					j4 = i7;
					break;

				case 18: // '\022'
					k4 = i7;
					break;

				case 19: // '\023'
					l4 = i7;
					break;

				case 20: // '\024'
					i5 = i7;
					break;

				case 21: // '\025'
					j5 = i7;
					break;

				case 22: // '\026'
					k5 = i7;
					break;

				case 23: // '\027'
					l5 = i7;
					break;

				case 24: // '\030'
					i6 = i7;
					break;
				}
			}
		}

		final int k6 = pc.getId();
		pc.sendPackets(new S_AddSkill(pc, j, k, l, i1, j1, k1, l1, i2, j2, k2,
				l2, i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5, i6, 0, 0,
				0, 0));
		pc.sendPacketsX8(new S_SkillSound(k6, 224));
		CharSkillReading.get().spellMastery(k6, i, s, 0, 0);
		pc.getInventory().removeItem(l1iteminstance, 1);
		pc.setSkillMastery(i);
	}

	public static void SpellBook3(L1PcInstance pc,
			L1ItemInstance l1iteminstance, ClientThread clientthread) {
		String s = "";
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;
		int i1 = 0;
		int j1 = 0;
		int k1 = 0;
		int l1 = 0;
		int i2 = 0;
		int j2 = 0;
		int k2 = 0;
		int l2 = 0;
		int i3 = 0;
		int j3 = 0;
		int k3 = 0;
		int l3 = 0;
		int i4 = 0;
		int j4 = 0;
		int k4 = 0;
		int l4 = 0;
		int i5 = 0;
		int j5 = 0;
		int k5 = 0;
		int l5 = 0;
		int i6 = 0;
		for (int j6 = 87; j6 <= 91; j6++) {
			final L1Skills l1skills = SkillsTable.getInstance().getTemplate(j6);
			final String s1 = new StringBuilder().append("技術書(")
					.append(l1skills.getName()).append(")").toString();
			if (l1iteminstance.getItem().getName().equalsIgnoreCase(s1)) {
				final int l6 = l1skills.getSkillLevel();
				final int i7 = l1skills.getId();
				s = l1skills.getName();
				i = l1skills.getSkillId();
				switch (l6) {
				case 1: // '\001'
					j = i7;
					break;

				case 2: // '\002'
					k = i7;
					break;

				case 3: // '\003'
					l = i7;
					break;

				case 4: // '\004'
					i1 = i7;
					break;

				case 5: // '\005'
					j1 = i7;
					break;

				case 6: // '\006'
					k1 = i7;
					break;

				case 7: // '\007'
					l1 = i7;
					break;

				case 8: // '\b'
					i2 = i7;
					break;

				case 9: // '\t'
					j2 = i7;
					break;

				case 10: // '\n'
					k2 = i7;
					break;

				case 11: // '\013'
					l2 = i7;
					break;

				case 12: // '\f'
					i3 = i7;
					break;

				case 13: // '\r'
					j3 = i7;
					break;

				case 14: // '\016'
					k3 = i7;
					break;

				case 15: // '\017'
					l3 = i7;
					break;

				case 16: // '\020'
					i4 = i7;
					break;

				case 17: // '\021'
					j4 = i7;
					break;

				case 18: // '\022'
					k4 = i7;
					break;

				case 19: // '\023'
					l4 = i7;
					break;

				case 20: // '\024'
					i5 = i7;
					break;

				case 21: // '\025'
					j5 = i7;
					break;

				case 22: // '\026'
					k5 = i7;
					break;

				case 23: // '\027'
					l5 = i7;
					break;

				case 24: // '\030'
					i6 = i7;
					break;
				}
			}
		}

		final int pcid = pc.getId();
		pc.sendPackets(new S_AddSkill(pc, j, k, l, i1, j1, k1, l1, i2, j2, k2,
				l2, i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5, i6, 0, 0,
				0, 0));
		// pc.sendPackets(new S_AddSkill(pc, i));
		pc.sendPacketsX8(new S_SkillSound(pcid, 224));
		CharSkillReading.get().spellMastery(pcid, i, s, 0, 0);
		pc.getInventory().removeItem(l1iteminstance, 1);
		pc.setSkillMastery(i);
	}

	public static void SpellBook4(L1PcInstance pc,
			L1ItemInstance l1iteminstance, ClientThread clientthread) {
		String s = "";
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;
		int i1 = 0;
		int j1 = 0;
		int k1 = 0;
		int l1 = 0;
		int i2 = 0;
		int j2 = 0;
		int k2 = 0;
		int l2 = 0;
		int i3 = 0;
		int j3 = 0;
		int k3 = 0;
		int l3 = 0;
		int i4 = 0;
		int j4 = 0;
		int k4 = 0;
		int l4 = 0;
		int i5 = 0;
		int j5 = 0;
		int k5 = 0;
		int l5 = 0;
		int i6 = 0;
		for (int j6 = 113; j6 < 121; j6++) {
			final L1Skills l1skills = SkillsTable.getInstance().getTemplate(j6);
			final String s1 = "魔法書 (" + l1skills.getName() + ")";
			if (l1iteminstance.getItem().getName().equalsIgnoreCase(s1)) {
				final int l6 = l1skills.getSkillLevel();
				final int i7 = l1skills.getId();
				s = l1skills.getName();
				i = l1skills.getSkillId();
				switch (l6) {
				case 1: // '\001'
					j = i7;
					break;

				case 2: // '\002'
					k = i7;
					break;

				case 3: // '\003'
					l = i7;
					break;

				case 4: // '\004'
					i1 = i7;
					break;

				case 5: // '\005'
					j1 = i7;
					break;

				case 6: // '\006'
					k1 = i7;
					break;

				case 7: // '\007'
					l1 = i7;
					break;

				case 8: // '\b'
					i2 = i7;
					break;

				case 9: // '\t'
					j2 = i7;
					break;

				case 10: // '\n'
					k2 = i7;
					break;

				case 11: // '\013'
					l2 = i7;
					break;

				case 12: // '\f'
					i3 = i7;
					break;

				case 13: // '\r'
					j3 = i7;
					break;

				case 14: // '\016'
					k3 = i7;
					break;

				case 15: // '\017'
					l3 = i7;
					break;

				case 16: // '\020'
					i4 = i7;
					break;

				case 17: // '\021'
					j4 = i7;
					break;

				case 18: // '\022'
					k4 = i7;
					break;

				case 19: // '\023'
					l4 = i7;
					break;

				case 20: // '\024'
					i5 = i7;
					break;

				case 21: // '\025'
					j5 = i7;
					break;

				case 22: // '\026'
					k5 = i7;
					break;

				case 23: // '\027'
					l5 = i7;
					break;

				case 24: // '\030'
					i6 = i7;
					break;
				}
			}
		}

		final int k6 = pc.getId();
		pc.sendPackets(new S_AddSkill(pc, j, k, l, i1, j1, k1, l1, i2, j2, k2,
				l2, i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5, i6, 0, 0,
				0, 0));
		pc.sendPacketsX8(new S_SkillSound(k6, 224));
		CharSkillReading.get().spellMastery(k6, i, s, 0, 0);
		pc.getInventory().removeItem(l1iteminstance, 1);
		pc.setSkillMastery(i);
	}

	public static void SpellBook5(L1PcInstance pc,
			L1ItemInstance l1iteminstance, ClientThread clientthread) {
		String s = "";
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;
		int i1 = 0;
		int j1 = 0;
		int k1 = 0;
		int l1 = 0;
		int i2 = 0;
		int j2 = 0;
		int k2 = 0;
		int l2 = 0;
		int i3 = 0;
		int j3 = 0;
		int k3 = 0;
		int l3 = 0;
		int i4 = 0;
		int j4 = 0;
		int k4 = 0;
		int l4 = 0;
		int i5 = 0;
		int j5 = 0;
		int k5 = 0;
		int l5 = 0;
		int i6 = 0;
		int i8 = 0;
		int j8 = 0;
		int k8 = 0;
		int l8 = 0;
		for (int j6 = 181; j6 <= 195; j6++) {
			final L1Skills l1skills = SkillsTable.getInstance().getTemplate(j6);
			final String s1 = "龍騎士書版 (" + l1skills.getName() + ")";
			if (l1iteminstance.getItem().getName().equalsIgnoreCase(s1)) {
				final int l6 = l1skills.getSkillLevel();
				final int i7 = l1skills.getId();
				s = l1skills.getName();
				i = l1skills.getSkillId();
				switch (l6) {
				case 1: // '\001'
					j = i7;
					break;

				case 2: // '\002'
					k = i7;
					break;

				case 3: // '\003'
					l = i7;
					break;

				case 4: // '\004'
					i1 = i7;
					break;

				case 5: // '\005'
					j1 = i7;
					break;

				case 6: // '\006'
					k1 = i7;
					break;

				case 7: // '\007'
					l1 = i7;
					break;

				case 8: // '\b'
					i2 = i7;
					break;

				case 9: // '\t'
					j2 = i7;
					break;

				case 10: // '\n'
					k2 = i7;
					break;

				case 11: // '\013'
					l2 = i7;
					break;

				case 12: // '\f'
					i3 = i7;
					break;

				case 13: // '\r'
					j3 = i7;
					break;

				case 14: // '\016'
					k3 = i7;
					break;

				case 15: // '\017'
					l3 = i7;
					break;

				case 16: // '\020'
					i4 = i7;
					break;

				case 17: // '\021'
					j4 = i7;
					break;

				case 18: // '\022'
					k4 = i7;
					break;

				case 19: // '\023'
					l4 = i7;
					break;

				case 20: // '\024'
					i5 = i7;
					break;

				case 21: // '\025'
					j5 = i7;
					break;

				case 22: // '\026'
					k5 = i7;
					break;

				case 23: // '\027'
					l5 = i7;
					break;

				case 24: // '\030'
					i6 = i7;
					break;

				case 25: // '\031'
					j8 = i7;
					break;

				case 26: // '\032'
					k8 = i7;
					break;

				case 27: // '\033'
					l8 = i7;
					break;
				case 28: // '\034'
					i8 = i7;
					break;
				}
			}
		}

		final int k6 = pc.getId();
		pc.sendPackets(new S_AddSkill(pc, j, k, l, i1, j1, k1, l1, i2, j2, k2,
				l2, i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5, i6, j8, k8,
				l8, i8));
		pc.sendPacketsX8(new S_SkillSound(k6, 224));
		CharSkillReading.get().spellMastery(k6, i, s, 0, 0);
		pc.getInventory().removeItem(l1iteminstance, 1);
		pc.setSkillMastery(i);
	}

	public static void SpellBook6(L1PcInstance pc,
			L1ItemInstance l1iteminstance, ClientThread clientthread) {
		String s = "";
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;
		int i1 = 0;
		int j1 = 0;
		int k1 = 0;
		int l1 = 0;
		int i2 = 0;
		int j2 = 0;
		int k2 = 0;
		int l2 = 0;
		int i3 = 0;
		int j3 = 0;
		int k3 = 0;
		int l3 = 0;
		int i4 = 0;
		int j4 = 0;
		int k4 = 0;
		int l4 = 0;
		int i5 = 0;
		int j5 = 0;
		int k5 = 0;
		int l5 = 0;
		int i6 = 0;
		int i8 = 0;
		int j8 = 0;
		int k8 = 0;
		int l8 = 0;
		for (int j6 = 201; j6 <= 220; j6++) {
			final L1Skills l1skills = SkillsTable.getInstance().getTemplate(j6);
			final String s1 = "記憶水晶 (" + l1skills.getName() + ")";
			if (l1iteminstance.getItem().getName().equalsIgnoreCase(s1)) {
				final int l6 = l1skills.getSkillLevel();
				final int i7 = l1skills.getId();
				s = l1skills.getName();
				i = l1skills.getSkillId();
				switch (l6) {
				case 1: // '\001'
					j = i7;
					break;

				case 2: // '\002'
					k = i7;
					break;

				case 3: // '\003'
					l = i7;
					break;

				case 4: // '\004'
					i1 = i7;
					break;

				case 5: // '\005'
					j1 = i7;
					break;

				case 6: // '\006'
					k1 = i7;
					break;

				case 7: // '\007'
					l1 = i7;
					break;

				case 8: // '\b'
					i2 = i7;
					break;

				case 9: // '\t'
					j2 = i7;
					break;

				case 10: // '\n'
					k2 = i7;
					break;

				case 11: // '\013'
					l2 = i7;
					break;

				case 12: // '\f'
					i3 = i7;
					break;

				case 13: // '\r'
					j3 = i7;
					break;

				case 14: // '\016'
					k3 = i7;
					break;

				case 15: // '\017'
					l3 = i7;
					break;

				case 16: // '\020'
					i4 = i7;
					break;

				case 17: // '\021'
					j4 = i7;
					break;

				case 18: // '\022'
					k4 = i7;
					break;

				case 19: // '\023'
					l4 = i7;
					break;

				case 20: // '\024'
					i5 = i7;
					break;

				case 21: // '\025'
					j5 = i7;
					break;

				case 22: // '\026'
					k5 = i7;
					break;

				case 23: // '\027'
					l5 = i7;
					break;

				case 24: // '\030'
					i6 = i7;
					break;

				case 25: // '\031'
					j8 = i7;
					break;

				case 26: // '\032'
					k8 = i7;
					break;

				case 27: // '\033'
					l8 = i7;
					break;
				case 28: // '\034'
					i8 = i7;
					break;
				}
			}
		}

		final int k6 = pc.getId();
		pc.sendPackets(new S_AddSkill(pc, j, k, l, i1, j1, k1, l1, i2, j2, k2,
				l2, i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5, i6, j8, k8,
				l8, i8));
		pc.sendPacketsX8(new S_SkillSound(k6, 224));
		CharSkillReading.get().spellMastery(k6, i, s, 0, 0);
		pc.setSkillMastery(i);
		pc.getInventory().removeItem(l1iteminstance, 1);
	}

	public static void useElfSpellBook(L1PcInstance pc, L1ItemInstance item,
			int itemId) {
		final int level = pc.getLevel();
		// if ((pc.isElf() || pc.isGm()) && isLearnElfMagic(pc)) {
		if (pc.isElf() || pc.isGm()) {
			if (itemId >= 40232 && itemId <= 40234 && level >= 10) {
				SpellBook2(pc, item);
			} else if (itemId >= 40235 && itemId <= 40236 && level >= 20) {
				SpellBook2(pc, item);
			}
			if (itemId >= 40237 && itemId <= 40240 && level >= 30) {
				SpellBook2(pc, item);
			} else if (itemId >= 40241 && itemId <= 40243 && level >= 40) {
				SpellBook2(pc, item);
			} else if (itemId >= 40244 && itemId <= 40246 && level >= 50) {
				SpellBook2(pc, item);
			} else if (itemId >= 40247 && itemId <= 40248 && level >= 30) {
				SpellBook2(pc, item);
			} else if (itemId >= 40249 && itemId <= 40250 && level >= 40) {
				SpellBook2(pc, item);
			} else if (itemId >= 40251 && itemId <= 40252 && level >= 50) {
				SpellBook2(pc, item);
			} else if (itemId == 40253 && level >= 30) {
				SpellBook2(pc, item);
			} else if (itemId == 40254 && level >= 40) {
				SpellBook2(pc, item);
			} else if (itemId == 40255 && level >= 50) {
				SpellBook2(pc, item);
			} else if (itemId == 49316 && level >= 50) {// TODO 生命呼喚
				SpellBook2(pc, item);
			} else if (itemId == 40256 && level >= 30) {
				SpellBook2(pc, item);
			} else if (itemId == 40257 && level >= 40) {
				SpellBook2(pc, item);
			} else if (itemId >= 40258 && itemId <= 40259 && level >= 50) {
				SpellBook2(pc, item);
			} else if (itemId >= 40260 && itemId <= 40261 && level >= 30) {
				SpellBook2(pc, item);
			} else if (itemId == 40262 && level >= 40) {
				SpellBook2(pc, item);
			} else if (itemId >= 40263 && itemId <= 40264 && level >= 50) {
				SpellBook2(pc, item);
			} else if (itemId >= 41149 && itemId <= 41150 && level >= 50) {
				SpellBook2(pc, item);
			} else if (itemId == 41151 && level >= 40) {
				SpellBook2(pc, item);
			} else if (itemId >= 41152 && itemId <= 41153 && level >= 50) {
				SpellBook2(pc, item);
			}
		} else {
			pc.sendPackets(new S_ServerMessage(79)); // (原文:精靈の水晶はエルフのみが習得できます。)
		}
	}

	public static void useSpellBook(L1PcInstance pc, L1ItemInstance item,
			int itemId) {
		// int itemAttr = 0;
		// int locAttr = 0; // 0:other 1:law 2:chaos
		// boolean isLawful = true;
		// final int pcX = pc.getX();
		// final int pcY = pc.getY();
		// final int mapId = pc.getMapId();
		final int level = pc.getLevel();
		// if (itemId == 45000 || itemId == 45008 || itemId == 45018
		// || itemId == 45021 || itemId == 40171 || itemId == 40179
		// || itemId == 40180 || itemId == 40182 || itemId == 40194
		// || itemId == 40197 || itemId == 40202 || itemId == 40206
		// || itemId == 40213 || itemId == 40220 || itemId == 40222) {
		// itemAttr = 1;
		// }else if (itemId == 45009 || itemId == 45010 || itemId == 45019
		// || itemId == 40172 || itemId == 40173 || itemId == 40178
		// || itemId == 40185 || itemId == 40186 || itemId == 40192
		// || itemId == 40196 || itemId == 40201 || itemId == 40204
		// || itemId == 40211 || itemId == 40221 || itemId == 40225) {
		// itemAttr = 2;
		// }
		// ロウフルテンプル
		// if (pcX > 33116 && pcX < 33128 && pcY > 32930 && pcY < 32942
		// && mapId == 4 || pcX > 33135 && pcX < 33147 && pcY > 32235
		// && pcY < 32247 && mapId == 4 || pcX >= 32783 && pcX <= 32803
		// && pcY >= 32831 && pcY <= 32851 && mapId == 77) {
		// locAttr = 1;
		// isLawful = true;
		// }
		// // カオティックテンプル
		// if (pcX > 32880 && pcX < 32892 && pcY > 32646 && pcY < 32658
		// && mapId == 4 || pcX > 32662 && pcX < 32674 && pcY > 32297
		// && pcY < 32309 && mapId == 4) {
		// locAttr = 2;
		// isLawful = false;
		// }
		// if (pc.isGm()) {
		// SpellBook(pc, item, isLawful);
		// } else
		// if ((itemAttr == locAttr || itemAttr == 0) && locAttr != 0) {
		if (pc.isKnight()) {
			if (itemId >= 45000 && itemId <= 45007 && level >= 50) {
				SpellBook(pc, item);
			} else if (itemId >= 45000 && itemId <= 45007) {
				pc.sendPackets(new S_ServerMessage(312));
			} else {
				pc.sendPackets(new S_ServerMessage(79));
			}
		} else if (pc.isCrown() || pc.isDarkelf()) {
			if (itemId >= 45000 && itemId <= 45007 && level >= 10) {
				SpellBook(pc, item);
			} else if (itemId >= 45008 && itemId <= 45015 && level >= 20) {
				SpellBook(pc, item);
			} else if (itemId >= 45008 && itemId <= 45015 || itemId >= 45000
					&& itemId <= 45007) {
				pc.sendPackets(new S_ServerMessage(312)); // レベルが低くてその魔法を覺えることができません。
			} else {
				pc.sendPackets(new S_ServerMessage(79)); // \f1何も起きませんでした。
			}
		} else if (pc.isElf()) {
			if (itemId >= 45000 && itemId <= 45007 && level >= 8) {
				SpellBook(pc, item);
			} else if (itemId >= 45008 && itemId <= 45015 && level >= 16) {
				SpellBook(pc, item);
			} else if (itemId >= 45016 && itemId <= 45022 && level >= 24) {
				SpellBook(pc, item);
			} else if (itemId >= 40170 && itemId <= 40177 && level >= 32) {
				SpellBook(pc, item);
			} else if (itemId >= 40178 && itemId <= 40185 && level >= 40) {
				SpellBook(pc, item);
			} else if (itemId >= 40186 && itemId <= 40193 && level >= 48) {
				SpellBook(pc, item);
			} else if (itemId >= 45000 && itemId <= 45022 || itemId >= 40170
					&& itemId <= 40193) {
				pc.sendPackets(new S_ServerMessage(312)); // レベルが低くてその魔法を覺えることができません。
			} else {
				pc.sendPackets(new S_ServerMessage(79)); // \f1何も起きませんでした。
			}
		} else if (pc.isWizard()) {
			if (itemId >= 45000 && itemId <= 45007 && level >= 4) {
				SpellBook(pc, item);
			} else if (itemId >= 45008 && itemId <= 45015 && level >= 8) {
				SpellBook(pc, item);
			} else if (itemId >= 45016 && itemId <= 45022 && level >= 12) {
				SpellBook(pc, item);
			} else if (itemId >= 40170 && itemId <= 40177 && level >= 16) {
				SpellBook(pc, item);
			} else if (itemId >= 40178 && itemId <= 40185 && level >= 20) {
				SpellBook(pc, item);
			} else if (itemId >= 40186 && itemId <= 40193 && level >= 24) {
				SpellBook(pc, item);
			} else if (itemId >= 40194 && itemId <= 40201 && level >= 28) {
				SpellBook(pc, item);
			} else if (itemId >= 40202 && itemId <= 40209 && level >= 32) {
				SpellBook(pc, item);
			} else if (itemId >= 40210 && itemId <= 40217 && level >= 36) {
				SpellBook(pc, item);
			} else if (itemId >= 40218 && itemId <= 40225 && level >= 40) {
				SpellBook(pc, item);
			} else {
				pc.sendPackets(new S_ServerMessage(312)); // レベルが低くてその魔法を覺えることができません。
			}
		}
		// } else if (itemAttr != locAttr && itemAttr != 0 && locAttr != 0) {//
		// 間違ったテンプルで讀んだ場合雷が落ちる
		// pc.sendPackets(new S_ServerMessage(79)); // \f1何も起きませんでした。
		// S_SkillSound effect = new S_SkillSound(pc.getId(), 10);
		// pc.sendPackets(effect);
		// pc.broadcastPacket(effect);// ダメージは適當
		// pc.setCurrentHp(Math.max(pc.getCurrentHp() - 45, 0));
		// if (pc.getCurrentHp() <= 0) {
		// new PcDeath().death(pc,null);
		// }
		// pc.getInventory().removeItem(item, 1);
		// } else {
		// pc.sendPackets(new S_ServerMessage(79)); // \f1何も起きませんでした。
		// }
	}

	/*
	 * private static boolean isLearnElfMagic(L1PcInstance pc) { final int pcX =
	 * pc.getX(); final int pcY = pc.getY(); final int pcMapId = pc.getMapId();
	 * if (pcX >= 32786 && pcX <= 32797 && pcY >= 32842 && pcY <= 32859 &&
	 * pcMapId == 75 // 象牙の塔 || pc.getLocation().isInScreen(new Point(33055,
	 * 32336)) && pcMapId == 4) { // マザーツリー return true; } return false; }
	 */

}
